<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<TITLE>卡片库存调整管理</TITLE>
		<script LANGUAGE="javascript" src="../script/common.js"  type="text/javascript"></script>
		<script type="text/javascript" src="../script/print.js"></script>
		<script language="javascript"  type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位	
			var qt = {};				//数据表格对象
			//页面加载方法
			function load(){ 
				Eui.showNavigation();
				searchForm.location.value = org.id;
				Common.initDict(adjustForm.cardStatus,CardStore.getStoreStatus(),"全 部");	
				Eui.initBeginDateInput("beginDateTd","起始日期","searchForm","beginDate","endDate","_pastDate");
				Eui.initEndDateInput("endDateTd","结束日期","searchForm","beginDate","endDate","_pastDate");
				
				var adjustStatus = Common.getSubsetItems(CardStoreStatus.CATEGORY, [CardStoreStatus.STORE, CardStoreStatus.LOST, CardStoreStatus.DAMAGED]);
			 	//调整前卡片库存状态
			 	Common.initDict("beforAdjustStatus",adjustStatus,"请选择");	
				
			 	// 调整后卡片库存状态
			 	Common.initDict("afterAdjustStatus",adjustStatus,"请选择");	
			 	
				Common.initDict(searchForm.cardStatus,CardStore.getStoreStatus(),"全 部");
				setPages(["listview","detview","amply","printBillDetail"]);	
				createTable();	
			}  
			//生成表格，创建QueryTable对象(查询)
			function createTable(){
				var columns = [];
				columns[0] = {render:nameFunc};		
				columns[6] = {defOrder:true};													
				columns[7] = {title:"操作",width:"18%",render:operator,align:"center",order:false} 
				qt = new QueryTable("card_store_adjust_query","searchForm","datalist",columns,{
					buttons:[
						{value:"添加调整单",actions:addAdjustBill}
					]
				});
			}
			
			//处理数据 点姓名进入编辑页面
			function nameFunc(v,r){
				return "<a href=# onclick=\"onLook("+r[0]+");return false;\">"+v+"</a>"
			}
			function operator(v,r){
				return "<div style='color:gray'><a href=# onclick=\"onConfirm("+r[0]+","+r[5]+");return false;\">调整</a> <a href=# onclick=updateBill('"+r[0]+"')>修改</a> <a href=# onclick=onDelete('"+r[0]+"')>删除</a></div>";
			}
			function updateBill(id){
				var butCancel =  "<button type='button' onclick='onConfirm()'>调 整</button>";
				requestframe.document.location.href = "card_bill_detail.html?cardBillId="+id+"&butCancel="+butCancel;
				switchPage("amply");
			}
			function onConfirm(id,amount){
				if(amount == 0){
					showInformation("调整数量不能为零!");return;
				}
				if(!(showQuestion("确定调整库存吗?"))){
					return;
				}
				DWR.call("cardStoreService.confirmAdjustInventory",id,function(cardBill){
					showInformation("库存调整成功!");
					printBill(cardBill);
					switchPage('printBillDetail');
				},{blockScreen:"true"});
			}
			function onDelete(id){
				if(!(showQuestion("确定删除吗?"))){
					return;
				}
				DWR.call("cardStoreService.deleteCardBill",id,function(){
					showInformation("删除成功!");
					qt.showTable();
					switchPage('listview');
				},{blockScreen:"true"});
			}
			//进入明细页面
			function onLook(id,printDispaly){
				requestframe.document.location.href = "card_bill_detail.html?readOnly=true&cardBillId="+id+"&printDispaly="+printDispaly;
				switchPage("amply");
			}
			
			function selCardType(){			
				var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700)
				if (v){
					searchForm.cardType.value = v[1]; 	 
				}
			}
			function addAdjustBill(){
				$("adjustForm").reset();
				switchPage("detview");
			}
			function onSave(){
			
				if(!checkForm(adjustForm))return;
				
				if(adjustForm.beforAdjustStatus.value == adjustForm.afterAdjustStatus.value){
					showWarning("调整前卡片库存状态不能与调整后卡片库存状态相同"); return
				}
				if(showQuestion("您确认要新建库存调整单吗?")){
					var cardTypeId = $("cardTypeId").value;
					var cardStatus = $("adjustForm").cardStatus.value;
					var description = $("description").value;
					var beforAdjustStatus = $("beforAdjustStatus").value;
					var afterAdjustStatus = $("afterAdjustStatus").value;
					DWR.call('cardStoreService.createCardBill', Constants.CARD_BILL_TYPE_ADJUST,cardTypeId,cardStatus,null,CardBillSubType.ADJUST_STOCK,description,beforAdjustStatus,afterAdjustStatus,function(v){
						var client = v.cardBill;	
						var butCancel =  "<button type='button' onclick='onConfirm()'>调 整</button>";
						requestframe.document.location.href = "card_bill_detail.html?cardBillId="+client.id+"&butCancel="+butCancel;
						
						switchPage("amply");
					},{disCtrl:$('saveBut')});
				}
			}
			function showData(){
			  	qt.showTable();
			}
			function onBack(){
				switchPage('listview');
				showData();
			}	
			
			function selCardType(form){			
				var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700)
				if (v){
					if(form == "adjustForm")
						$(form).cardTypeId.value=v[0];
					$(form).cardTypeName.value = v[1];
				}
			}
		</script>
	</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<!--查询静态页面部分-->
	<div id="listview" >	
		<!--查询条件form-->
		<div class="searchForm">
			<form id="searchForm" name="searchForm">
				<input type="hidden" id="location" name="location">
				<table cellSpacing=0 cellPadding=4 width="100%" border=0>
					<tr>
						<td><label>单据编号</label> <input type="text" name="adjustid" onblur="checkV(this,'number')" maxlength=12></td>
						<td><label>卡片类型</label> <input type="text" name="cardTypeName"><a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType('searchForm')">&nbsp;&nbsp;</a></td>							
						<td><label>卡片状态</label> <select name="cardStatus" ><option></option></select></td>
						
					</tr>
					<tr>
						<td id="beginDateTd"></td>
						<td id="endDateTd"></td>
						<td><button type="button" onclick="showData()">查 询</button></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="datalist"></div>	
	</div>		
	<!--明细静态页面部分-->
	<div id="detview" style="display:none;">
		<form id="adjustForm" name="adjustForm">
			<input type="hidden" name="cardTypeId">
			<div class="form">
				<div class="formTitle">库存调整单</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label9">
					<tr>
					  	<td><label>卡片类型</label> <input type="text" name="cardTypeName" readonly class="readonly" onblur="checkV(this,'',true)" ><a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType('adjustForm')">&nbsp;&nbsp;</a><span class="des">*</span></td>
				  		<td><label>卡片状态</label> <select name="cardStatus" onblur="checkV(this,'',true)"><option></option></select><span class="des">*</span></td>
					</tr>
					<tr>		
						<td><label>调整前卡片库存状态</label> <select name="beforAdjustStatus" onblur="checkV(this,'',true)"><option></option></select><span class="des">*</span></td>
						<td><label>调整后卡片库存状态</label> <select name="afterAdjustStatus" onblur="checkV(this,'',true)"><option></option></select><span class="des">*</span></td>
					</tr>	
					<tr>		
						<td><label>调整原因</label> <input name="description" maxlength="32" onblur="checkV(this,'',true)"><span class="des">*</span></td>
					</tr>	
						
				</table>
			</div>
			  <p><button type="button" id="saveBut" onclick="onSave()">下一步</button> <button type="button" onclick="switchPage('listview');">返  回</button></p>
		</form>	
	</div>
	
	<div id="amply" style="display:none;">	
		<iframe name="requestframe" name="requestframe" marginwidth=0 marginheight=0 width=100% height=520 src="" frameborder=0></iframe>
	</div>
	<div id="printBillDetail" class="form" style="display:none;">
		<div class="formTitle">
			<div class="l">单据预览</div>
			<div class="r">
				<button onclick="WebPrint.preview('content')">打印预览</button>
		 		<button onclick="WebPrint.print('content')">打印</button>
		 		<button onclick="onBack()">返回</button>
			</div>
		</div>
		<div  id="content" align='center'></div>
	</div>
</body>
</HTML>